# -*- coding: utf-8 -*-

from django.db import models
from django.utils.translation import ugettext_lazy as _


class Report(models.Model):

    name_start = models.CharField(verbose_name=_(u'Player start name'), max_length=200, blank=False, null=False)
    name_finish = models.CharField(verbose_name=_(u'Player finish name'), max_length=200, blank=False, null=False)
    #base_start = models.ForeignKey('game.Base', verbose_name=_(u"Base Start"), blank=False, null=False, related_name='report_start') # por qué foreignkeys a bases..? ES POSIBLE QE HAYA QUE ELIMINAR ÉSTO...
    #base_finish = models.ForeignKey('game.Base', verbose_name=_(u"Base Finish"), blank=False, null=False, related_name='report_finish')

    # enlazarlo con game

    info = models.TextField(verbose_name=_(u'BattleReport Information'), max_length=2000, blank=False, null=False)
    date_created = models.DateTimeField(null=False, auto_now_add=True)

    def __unicode__(self):
        return unicode(self.id) + u' -- ' + unicode(self.name_start) + u' vs ' + unicode(self.name_finish)

    class Meta:
        app_label = 'game'
        verbose_name = _(u'Report')
        verbose_name_plural = _(u'Reports')


class MovementReport(Report):

    movement = models.OneToOneField('game.MovementResources', verbose_name="Resource Movement", related_name='movement_report', blank=False, null=False)
    
    class Meta:
        app_label = 'game'
        verbose_name = _(u'Movement Report')
        verbose_name_plural = _(u'Movement Reports')


class UpholdReport(Report):

    uphold = models.OneToOneField('game.Uphold', verbose_name="Uphold", related_name='uphold_report', blank=False, null=False)
    ants_uphold_init = models.CommaSeparatedIntegerField(verbose_name=_('Num Ants Uphold Initial'), max_length=255, blank=False, null=False)
    ants_uphold_finish = models.CommaSeparatedIntegerField(verbose_name=_('Num Ants Uphold Finished'), max_length=255, blank=False, null=False)

    class Meta:
        app_label = 'game'
        verbose_name = _(u'Uphold Report')
        verbose_name_plural = _(u'Uphold Reports')

    def get_ants_uphold_init_list(self):
        return eval("[" + self.ants_uphold_init + "]")

    def get_ants_uphold_finish_list(self):
        return eval("[" + self.ants_uphold_finish + "]")


class BattleReport(Report):

    attack = models.OneToOneField('game.Attack', verbose_name="Attack", related_name='battle_report', blank=False, null=False)
    ants_attack_start = models.CommaSeparatedIntegerField(verbose_name=_('Num Ants Attack Start'), max_length=255, blank=False, null=False)
    ants_attack_finish = models.CommaSeparatedIntegerField(verbose_name=_('Num Ants Attack Finish'), max_length=255, blank=False, null=False)
    ants_defend_start = models.CommaSeparatedIntegerField(verbose_name=_('Num Ants Defend Start'), max_length=255, blank=False, null=False)
    ants_defend_finish = models.CommaSeparatedIntegerField(verbose_name=_('Num Ants Defend Finish'), max_length=255, blank=False, null=False)
    invisible = models.BooleanField(verbose_name=_('Invisible Report'), blank=False, null=False, default=False)

    class Meta:
        app_label = 'game'
        verbose_name = _(u'Battle Report')
        verbose_name_plural = _(u'Battle Reports')

    def get_ants_attack_start_list(self):
        return eval("[" + self.ants_attack_start + "]")

    def get_ants_attack_finish_list(self):
        return eval("[" + self.ants_attack_finish + "]")

    def get_ants_attack_deads_list(self):
        ants_attack_deads = []
        count = 0
        ants_attack_start = self.get_ants_attack_start_list()
        ants_attack_finish = self.get_ants_attack_finish_list()
        while count < len(ants_attack_start):
            ants_attack_deads.append(ants_attack_start[count] - ants_attack_finish[count])
            count += 1
        return ants_attack_deads


    def get_ants_defend_start_list(self, invisible=False):
        if invisible:
            return ["?", "?", "?", "?", "?", "?"]
        else:
            return eval("[" + self.ants_defend_start + "]")

    def get_ants_defend_finish_list(self, invisible=False):
        if invisible:
            return ["?", "?", "?", "?", "?", "?"]
        else:
            return eval("[" + self.ants_defend_finish + "]")

    def get_ants_defend_deads_list(self, invisible=False):
        if invisible:
            return ["?", "?", "?", "?", "?", "?"]
        else:
            ants_defend_deads = []
            count = 0
            ants_defend_start = self.get_ants_defend_start_list()
            ants_defend_finish = self.get_ants_defend_finish_list()
            while count < len(ants_defend_start):
                ants_defend_deads.append(ants_defend_start[count] - ants_defend_finish[count])
                count += 1
            return ants_defend_deads


"""
class AcechoReport(Report):
"""

